package resp

var ErrorStatusReflect = make(map[string]int)
var ErrorMsgReflect = make(map[string]string)

func init() {
	ErrorStatusReflect["OK"] = 200
	ErrorStatusReflect["AUTH"] = 401
	ErrorStatusReflect["DENY"] = 403
	ErrorStatusReflect["PARAM"] = 400
	ErrorStatusReflect["NOT_FOUND"] = 401
	ErrorStatusReflect["SERVER"] = 500

	ErrorMsgReflect["OK"] = "OK"
	ErrorMsgReflect["AUTH"] = "请求的凭据无效"
	ErrorMsgReflect["DENY"] = "无权限访问"
	ErrorMsgReflect["PARAM"] = "请求错误"
	ErrorMsgReflect["NOT_FOUND"] = "对象不存在"
	ErrorMsgReflect["SERVER"] = "服务器内部错误"
}

type RespPack struct {
	Code    int
	Message string
	Status  int
	Data    interface{}
}

func GetInfo(errType string, msg string) *RespPack {
	errorStatus := ErrorStatusReflect["PARAM"]
	errorMsg := ErrorMsgReflect["PARAM"]

	_, exist := ErrorStatusReflect[errType]

	if exist {
		errorStatus = ErrorStatusReflect[errType]

		if msg != "" {
			errorMsg = msg
		} else {
			errorMsg = ErrorMsgReflect[errType]
		}
	}

	infoObject := RespPack{Message: errorMsg, Status: errorStatus, Code: errorStatus}

	return &infoObject
}
